<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <body>

        <ui:composition template="./topbartemplate.xhtml">

            <ui:define name="content">
                <h:form>
                    <p:wizard>
                        <p:tab id="informations" title="Informations">
                            <p:panel header="Event Informations">
                                <p:messages />
                                <h:panelGrid id="informationsgrid" columns="2" columnClasses="label, value">
                                    <p:outputLabel for="eventName" value="Event name:"/>
                                    <p:inputText  id="eventName" required="true" value="#{createEventBean.event.name}" />
                                    <p:outputLabel for="eventPlace" value="Event place:"/>
                                    <p:inputText  id="eventPlace" required="true" value="#{createEventBean.event.place}"/>
                                    <p:outputLabel for="eventaAddress" value="Address:"/>
                                    <p:inputText  id="eventaAddress" required="true" value="#{createEventBean.event.address}"/>

                                    <p:outputLabel for="country" value="Country:" />
                                    <p:selectOneMenu id="country" value="#{createEventBean.event.country}" style="width:150px" required="true">
                                        <p:ajax listener="#{createEventBean.onCountryChange}" update="city" />
                                        <f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
                                        <f:selectItems value="#{createEventBean.countries}" />
                                    </p:selectOneMenu>

                                    <p:outputLabel for="city" value="City: " />
                                    <p:selectOneMenu id="city" value="#{createEventBean.event.city}" style="width:150px" required="true">
                                        <f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
                                        <f:selectItems value="#{createEventBean.cities}" />
                                    </p:selectOneMenu>

                                    <p:outputLabel for="starttime" value="Start event:" />
                                    <p:calendar id="starttime" value="#{createEventBean.event.startTime}" navigator="true" effect="fold" pattern="dd/MM/yyyy HH:mm:ss" required="true">
                                         <p:ajax event="dateSelect" update="endtime" />
                                    </p:calendar>
                                    
                                    <p:outputLabel for="endtime" value="End event:" />
                                    <p:calendar id="endtime" value="#{createEventBean.event.endTime}" navigator="true" effect="fold" pattern="dd/MM/yyyy HH:mm:ss" required="true" validator="#{createEventBean.validateEndDate}" >
                                         <p:ajax event="dateSelect" update="starttime" />  
                                    </p:calendar>

                                    <p:outputLabel for="outdoor" value="Outdoor:" />
                                    <p:selectBooleanButton id="outdoor" value="#{createEventBean.event.outdoor}" required="true" onLabel="Yes" offLabel="No" onIcon="ui-icon-check" style="width:60px" />
                                </h:panelGrid>
                            </p:panel>
                        </p:tab>

                        <p:tab id="invitations" title="Invitations">
                            <p:panel header="Invitations">
                                <p:messages />
                                <h:panelGrid columns="3" cellpadding="5">
                                    <h:outputLabel for="invitationMenu" value="Invitations:" />
                                    <p:selectCheckboxMenu id="invitationMenu" value="#{createEventBean.invitations}" label="Users" filter="true" filterMatchMode="startsWith" panelStyle="width:250px">
                                        <f:selectItems value="#{createEventBean.users}" />
                                    </p:selectCheckboxMenu>
                                    <p:commandLink value="Submit" update="invitationList" />
                                </h:panelGrid>

                                <p:outputPanel id="invitationList" style="width:250px;padding-left:5px;margin-top:10px">
                                    <p:dataList value="#{createEventBean.invitations}" var="invitation" emptyMessage="No users selected" >
                                         #{invitation}
                                    </p:dataList>
                                </p:outputPanel>
                            </p:panel>
                        </p:tab>

                        <p:tab id="badweather" title="Bad weather">
                            <p:panel header="Bad weather definition">
                             
                                <h:panelGrid columns="5" columnClasses="label, value, label, value">
                                    <p:outputLabel for="isMinTemp" value="Enable min. temperature:"/>
                                    <p:selectBooleanCheckbox id="isMinTemp" value="#{createEventBean.setMinTemperature}">
                                        <p:ajax update="minTemperature" listener="#{createEventBean.changeEnabledMinTemperature}" />
                                    </p:selectBooleanCheckbox>
                                    <h:outputLabel for="minTemperature" value="Min. temperature (°C):" />
                                    <p:spinner id="minTemperature" value="#{createEventBean.minTemperature}" stepFactor="0.5" min="#{createEventBean.minTemperatureAvaiable}" max="#{createEventBean.maxTemperatureAvaiable}" disabled="true" binding="#{createEventBean.minTemperatureUI}">
                                        <p:ajax update="@this" />
                                    </p:spinner>
                                    <p:message for="minTemperature" />
                                    <p:outputLabel for="isMaxTemp" value="Enable max. temperature:"/>
                                    <p:selectBooleanCheckbox id="isMaxTemp" value="#{createEventBean.setMaxTemperature}">
                                        <p:ajax update="maxTemperature" listener="#{createEventBean.changeEnabledMaxTemperature}" />
                                    </p:selectBooleanCheckbox>
                                    <h:outputLabel for="maxTemperature" value="Max. temperature (°C):" />
                                    <p:spinner id="maxTemperature" value="#{createEventBean.maxTemperature}" stepFactor="0.5" min="#{createEventBean.minTemperatureAvaiable}" max="#{createEventBean.maxTemperatureAvaiable}" disabled="true" binding="#{createEventBean.maxTemperatureUI}" validator="#{createEventBean.validateMaximumTemperature}">
                                        <p:ajax update="@this" />
                                    </p:spinner>
                                    <p:message for="maxTemperature" />
                                </h:panelGrid>

                                <h:panelGrid columns="2" style="margin-bottom:10px">
                                    <p:outputLabel for="badweathers" value="Bad weathers:" />
                                    <p:selectManyCheckbox id="badweathers" value="#{createEventBean.selectedWeatherTypes}" layout="grid" columns="3" >
                                        <f:selectItem itemLabel="Clear sky" itemValue="Clear sky" />
                                        <f:selectItem itemLabel="Few clouds" itemValue="Few clouds" />
                                        <f:selectItem itemLabel="Scattered clouds" itemValue="Scattered clouds" />
                                        <f:selectItem itemLabel="Broken clouds" itemValue="Broken clouds" />
                                        <f:selectItem itemLabel="Shower rain" itemValue="Shower rain" />
                                        <f:selectItem itemLabel="Rain" itemValue="Rain" />
                                        <f:selectItem itemLabel="Thunderstorm" itemValue="Thunderstorm" />
                                        <f:selectItem itemLabel="Snow" itemValue="Snow" />
                                        <f:selectItem itemLabel="Mist" itemValue="Mist" />
                                    </p:selectManyCheckbox>
                                </h:panelGrid>
                            </p:panel>
                        </p:tab>

                        <p:tab id="confirm" title="Confirmation">
                            <p:panel header="Confirmation">
                                <h:panelGrid id="informationsConfirmation" columns="4" columnClasses="label, value, label, value">
                                    
                                    <h:outputText value="Event name:" />
                                    <h:outputText value="#{createEventBean.event.name}" style="font-weight: bold" />
                                    <h:outputText value="Event place:" />
                                    <h:outputText value="#{createEventBean.event.place}" style="font-weight: bold" />
                                    <h:outputText value="Address:" />
                                    <h:outputText value="#{createEventBean.event.address}" style="font-weight: bold" />
                                    <h:outputText value="Country:" />
                                    <h:outputText value="#{createEventBean.event.country}" style="font-weight: bold" />
                                    <h:outputText value="City:" />
                                    <h:outputText value="#{createEventBean.event.city}" style="font-weight: bold" />
                                    <h:outputText value="Outdoor:" />
                                    <h:outputText value="#{createEventBean.outdoorWellFormatted}" style="font-weight: bold" />
                                    <h:outputText value="Start event:" />
                                    <h:outputText value="#{createEventBean.event.startTime}" style="font-weight: bold" />
                                    <h:outputText value="End event:" />
                                    <h:outputText value="#{createEventBean.event.endTime}" style="font-weight: bold" />
                                                                      
                                </h:panelGrid>
                                <p:spacer width="100" height="10" />
                                <p:outputPanel id="invitationListConfirmation" style="width:250px;margin-top:10px">
                                    <p:dataList value="#{createEventBean.invitations}" var="invitation" emptyMessage="No users selected" >
                                        <f:facet name="header">
                                            Invitations
                                        </f:facet>
                                         #{invitation}
                                    </p:dataList>
                                </p:outputPanel>
                                <p:spacer width="100" height="10" />
                                <h:panelGrid id="badWeatherConfirmation" columns="2" columnClasses="label, value">
                                    <h:outputText value="Min. temperature:" />
                                    <h:outputText value="#{createEventBean.minTemperatureString}" style="font-weight: bold" />
                                    <h:outputText value="Max temperature:" />
                                    <h:outputText value="#{createEventBean.maxTemperatureString}" style="font-weight: bold" />
                                    <h:outputText value="Bad weathers:" />
                                    <h:outputText value="#{createEventBean.badWeathersWellFormatted}" style="font-weight: bold" />
                                </h:panelGrid>
                                <p:separator/>
                                <h:outputText value="The following weather condition is expected for your event: "/>
                                <h:outputText value="#{createEventBean.weatherForecast}" style="font-weight: bold"/>
                            </p:panel>
                            <p:commandButton value="Create" action="#{createEventBean.create}" actionListener="#{createEventBean.confirmCreation}"  style="float:right;" update="@all">
                                <p:confirm header="Confirmation" message="Create the event?" icon="ui-icon-alert" />
                            </p:commandButton>
                            
                            <p:confirmDialog global="true" showEffect="fade">
                                <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
                                <p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
                            </p:confirmDialog>
                        </p:tab>
                    </p:wizard>

                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
